﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using DataAccess.CustomerDAC;
using Framework;

namespace DomMgmtSystem
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                FormsAuthentication.SignOut();
                Session["userID"] = null;
                Session["UserModel"] = null;
            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                string userName = txtUserID.Value.Trim();
                string pwd = txtPwd.Value;
                CustomerDAC userDAC = new CustomerDAC();
                Model.TB_USER user = userDAC.GetModel(userName, pwd);
                if (user != null)
                {
                    Session["userID"] = userName;
                    Session["UserModel"] = user;
                    FormsAuthentication.SetAuthCookie(userName, false);
                    Response.Redirect("Index.aspx");
                }
                else
                {
                    this.Alert("登录失败,请检查输入的用户名和密码是否正确!");
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorFormat("Login exception:{0}{1}", ex.Message, ex.StackTrace);
                this.Alert("登录失败,系统出现异常!");
            }
        }
    }
}